﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：UserLevelList.aspx.cs
* 创建标识：曾乃强 15158756652 2011-3-21 10:12:44
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CNVP.Framework;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;


namespace CNVP.JShop.Web.Admin
{
    public partial class UserLevelList : AdminPage
    {
        BLL.CNVP_UserLevel bll = new BLL.CNVP_UserLevel();
        public int rplistCount = 0;
        public int PageIndex = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 91)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && Public.IsNumber(Request.QueryString["Page"]))
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            if (!IsPostBack)
            {
                StartLoad(PageIndex);
                btDelete.Attributes.Add("onclick", "if(ifCheck()){return confirm('确定删除该记录吗?');}else{alert('请选择记录！');return false;};");
            }
        }


        /// <summary>
        /// PageNavigator1_PageChange 的摘要说明
        /// 分页加载列表函数
        /// </summary>
        protected void StartLoad(int PageIndex)
        {
            int i, j;
            DataTable dt = null;
            int pageNum = 20;
            dt = bll.GetPage(this.GetType().Name, PageIndex, pageNum, out i, out j, null);
            rpList.DataSource = dt;
            rpList.DataBind();
            paging.InnerHtml = Paginator.Pagination(PageIndex, i, j);
        }

        protected void btDelete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.rpList.Items.Count; i++)
            {
                CheckBox cbCheck = (CheckBox)this.rpList.Items[i].FindControl("cbCheck");
                if (cbCheck.Checked == true)
                {
                    int code = int.Parse(cbCheck.ToolTip);
                    var User_List = new BLL.CNVP_Users().GetAll_CNVP_Users("UserLevelID=" + code + "");
                    if (User_List.Count > 0)
                    {
                        BasePage.MessageBoxGoHistory("该等级存在会员中,不允许删除.！");
                        return;
                    }
                    else
                    {
                        bll.Delete_CNVP_UserLevel(code);
                    }
                }
            }
            StartLoad(PageIndex);
        }

        protected void rpList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //方法一
            if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
            {
                Label lbIsAcquiesce = (Label)e.Item.FindControl("lbIsAcquiesce");
                CheckBox cbCheck = (CheckBox)e.Item.FindControl("cbCheck");
                if (lbIsAcquiesce.Text.Trim() == "是")
                {
                    cbCheck.Enabled = false;
                }
                HyperLink HLinkAddUser = (HyperLink)e.Item.FindControl("HLinkAddUser");
                HLinkAddUser.NavigateUrl = "UserEdit.aspx?UserLevelID=" + cbCheck.ToolTip;
            }
        }

    }
}